/**
 * @author yinyunqi
 * @datetime 2018年2月7日
 * @Content 
 */
package com.yongqi.controller.back;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.yongqi.model.console.Bill;
import com.yongqi.service.console.BillService;

@Controller
@RequestMapping("/back/income")
public class BackIncomeController {
	@Autowired
	BillService billService;

	/**
	 * 后台收入管理
	 * 
	 * @return 收入主页
	 */
	@RequestMapping("/index")
	public String backIncomeIndex() {
		return "back/back_income";
	}

	/**
	 * 后台-收入管理-收入查询
	 */
	@ResponseBody
	@RequestMapping("/query")
	public String backIncomeQuery(@RequestParam int pageNumber, int pageSize, String id, String family,String date,String date_end) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", id);
		map.put("family", family);
		map.put("date", date);
		map.put("date_end",date_end);
		map.put("billType","income");
		int total = billService.backIncomeQuery(map).size();
		PageHelper.startPage(pageNumber, pageSize);
		List<Bill> familyList = billService.backIncomeQuery(map);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("rows", familyList);
		jsonObject.put("total", total);
		return jsonObject.toJSONString();
	}

	/**
	 * 后台-收入管理-收入删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	public String backIncomeDelete(@RequestParam String id) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", id);
		billService.backIncomeDeleteById(map);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("res", "success");
		return jsonObject.toJSONString();
	}
}
